<template>
  <basic-container>
    <avue-crud :option="option" :search.sync="search" :table-loading="loading" :data="data" :page.sync="page" :permission="permissionList" :before-open="beforeOpen" v-model="form" ref="crud" @row-update="rowUpdate" @row-save="rowSave" @row-del="rowDel" @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange" @sort-change="sortChange" @on-load="onLoad">
      <!-- <template slot-scope="scope" slot="menu">
        <el-button
          v-if="permission.store_view"
          icon="el-icon-view"
          size="small"
          type="text"
          @click.stop="handleDetail(scope.row, scope.index)"
          >详 情</el-button
        >
        <el-button
          v-if="permission.store_view"
          icon="el-icon-cpu"
          size="small"
          type="text"
          @click.stop="handleDevice(scope.row, scope.index)"
          >管理</el-button
        >
      </template> -->
      <template slot="menuLeft">
        <!-- <el-button
          type="primary"
          size="small"
          icon="el-icon-plus"
          v-if="permission.store_add"
          @click="handleStorage"
          >入 库
        </el-button> -->
        <el-button type="primary" size="small" icon="el-icon-sort-up" v-if="permission.store_add" @click="handleAllot">调 拨
        </el-button>
        <el-button type="primary" size="small" icon="el-icon-sort-down" v-if="permission.store_add" @click="handleRebate">回 拨
        </el-button>
        <!-- <el-button
          type="danger"
          size="small"
          icon="el-icon-delete"
          plain
          v-if="permission.store_delete"
          @click="handleDelete"
          >删 除
        </el-button> -->
      </template>
      <template slot="menuRight">
        <el-button
          type="warning"
          size="small"
          plain
          icon="el-icon-download"
          v-if="permission.store_export"
          @click="handleExport"
          >导出
        </el-button>
      </template>

      <template slot="menu" slot-scope="{row}">
        <el-button type="text" size="mini" icon="el-icon-setting" v-if="isMuen(row.aisleCode) && row.isBind !== 1" @click="setPolicyVisible(row)">机具费率</el-button>
      </template>
      <!-- <template slot-scope="{ row }" slot="isOn">
        <el-switch
          :active-value="1"
          :inactive-value="0"
          v-model="row.isOn"
          @change="handleSwitch(row)"
        >
        </el-switch>
      </template> -->
      <template slot-scope="{}" slot="serviceNoSearch">
        <select-page ref="searchSerSelect" label="serviceName" value="serviceNo" :select.sync="search.serviceNo" :url="website.searchLink.serviceUrl" placeholder-text="服务商" filter-key="searchParam"></select-page>
      </template>
      <template slot-scope="{}" slot="orgNoSearch">
        <select-page ref="searchOrgSelect" label="serviceName" value="serviceNo" :select.sync="search.orgNo" :url="website.searchLink.orgUrl" placeholder-text="所属机构" filter-key="searchParam"></select-page>
      </template>
      <template slot-scope="{}" slot="rpiNoSearch">
        <select-page ref="searchRpiSelect" label="rpiName" value="rpiNo" :select.sync="search.rpiNo" :url="website.searchLink.merchantUrl" placeholder-text="商户" filter-key="searchParam"></select-page>
      </template>
      <template slot-scope="{row}" slot="amount">
        <el-tag type="success" :color="getColorStatus(row.amount)" effect="dark">{{ row.amountName }}</el-tag>
      </template>
      <template slot-scope="{row}" slot="rpiNo">
        <span class="haruyuki-color-subjectbluelight cursor-pointer" @click="handleMarchantDetails(row)">{{ row.rpiNo }}</span>
      </template>

      <template slot-scope="{row}" slot="isBind">
        <el-tag type="success" :color="getColor(row.isBind)" effect="dark">{{ row.isBindName }}</el-tag>
      </template>
    </avue-crud>
    <!-- <el-dialog
      title="数据导入"
      append-to-body
      :visible.sync="excelBox"
      width="555px"
    >
      <avue-form
        :option="excelOption"
        v-model="excelForm"
        :upload-after="uploadAfter"
      >
        <template slot="excelTemplate">
          <el-button type="primary" @click="handleTemplate">
            点击下载<i class="el-icon-download el-icon--right"></i>
          </el-button>
        </template>
      </avue-form>
    </el-dialog> -->


    <!-- 菜单-机构数 -->
    <el-dialog v-if="policyVisible" title="机具费率" append-to-body :visible.sync="policyVisible" :before-close="policyHandleClose">
      <template>
        <!-- <div class="haruyuki-scrollbar-60vh haruyuki-p-10"> -->
        <div class="haruyuki-line-height-special haruyuki-plr-40 line_top">
          <span>微信签约费率：</span>
          <el-input-number size="mini" v-model="policyForm.wechatSignRate" :precision="4" :step="0.0001" :min="policyForm.wechatSignRateMin" :max="1"></el-input-number>
          <span> %</span>
          <span class="p-l-20">(最低微信签约费率：：{{ policyForm.wechatSignRateMin }} %)</span>
        </div>

        <div class="haruyuki-line-height-special haruyuki-plr-40 line_top">
          <span>支付宝签约费率：：</span>
          <el-input-number size="mini" v-model="policyForm.alipaySignRate" :precision="4" :step="0.0001" :min="policyForm.alipaySignRateMin" :max="1"></el-input-number>
          <span> %</span>
          <span class="p-l-20">(最低支付宝签约费率：：{{ policyForm.alipaySignRateMin }} %)</span>
        </div>

        <!-- 盛付通 A0000019-->
        <template v-if="aisleCode != 'A0000022'">
          <div class="haruyuki-line-height-special haruyuki-plr-40 line_top">
            <span>银联二维码小额借记卡费率：</span>
            <el-input-number size="mini" v-model="policyForm.debitRate2" :precision="4" :step="0.0001" :min="policyForm.debitRate2Min" :max="1"></el-input-number>
            <span> %</span>
            <span class="p-l-20">(最低银联二维码小额借记卡费率：{{ policyForm.debitRate2Min }} %)</span>
          </div>

          <div class="haruyuki-line-height-special haruyuki-plr-40 line_top">
            <span>银联二维码小额贷记卡优惠费率：</span>
            <el-input-number size="mini" v-model="policyForm.creditRate2" :precision="4" :step="0.0001" :min="policyForm.creditRate2Min" :max="1"></el-input-number>
            <span> %</span>
            <span class="p-l-20">(最低银联二维码小额贷记卡优惠费率：{{ policyForm.creditRate2Min }} %)</span>
          </div>

          <div class="haruyuki-line-height-special haruyuki-plr-40 line_top">
            <span>云闪付大额贷记卡费率：</span>
            <el-input-number size="mini" v-model="policyForm.unionpayRate" :precision="4" :step="0.0001" :min="policyForm.unionpayRateMin" :max="1"></el-input-number>
            <span> %</span>
            <span class="p-l-20">(最低云闪付大额贷记卡费率：{{ policyForm.unionpayRateMin }} %)</span>
          </div>

          <div class="haruyuki-line-height-special haruyuki-plr-40 line_top">
            <span>刷卡借记卡费率：</span>
            <el-input-number size="mini" v-model="policyForm.t111Rate" :precision="4" :step="0.0001" :min="policyForm.t111RateMin" :max="1"></el-input-number>
            <span> %</span>
            <span class="p-l-20">(最低刷卡借记卡费率：{{ policyForm.t111RateMin }} %)</span>
          </div>

          <div class="haruyuki-line-height-special haruyuki-plr-40 line_top">
            <span>刷卡借记卡封顶金额：</span>
            <el-input-number size="mini" v-model="policyForm.d011RateTop" :precision="2" :step="1" :min="policyForm.d011RateTopMin"></el-input-number>
            <span> 元 </span>
            <span class="p-l-20">(最低刷卡借记卡封顶金额：{{ policyForm.d011RateTopMin }} 元)</span>
          </div>

          <div class="haruyuki-line-height-special haruyuki-plr-40 line_top">
            <span>刷卡贷记卡费率：</span>
            <el-input-number size="mini" v-model="policyForm.t112Rate" :precision="4" :step="0.0001" :min="policyForm.t112RateMin" :max="1"></el-input-number>
            <span> %</span>
            <span class="p-l-20">(最低刷卡贷记卡费率：{{ policyForm.t112RateMin }} %)</span>
          </div>
        </template>

        <!-- 海科 -->
        <template v-if="aisleCode == 'A0000022'">
          <div class="haruyuki-line-height-special haruyuki-plr-40 line_top">
            <span>云闪付小额(&le;1000)费率：</span>
            <el-input-number size="mini" v-model="policyForm.unionpayRate" :precision="4" :step="0.0001" :min="policyForm.unionpayRateMin" :max="1"></el-input-number>
            <span> %</span>
            <span class="p-l-20">(最低云闪付小额(&le;1000)费率：{{ policyForm.unionpayRateMin }} %)</span>
          </div>

          <div class="haruyuki-line-height-special haruyuki-plr-40 line_top">
            <span>刷卡贷记卡费率：</span>
            <el-input-number size="mini" v-model="policyForm.t112Rate" :precision="4" :step="0.0001" :min="policyForm.t112RateMin" :max="1"></el-input-number>
            <span> %</span>
            <span class="p-l-20">(最低刷卡贷记卡费率：{{ policyForm.t112RateMin }} %)</span>
          </div>

          <div class="haruyuki-line-height-special haruyuki-plr-40 line_top">
            <span>刷卡借记卡费率：</span>
            <el-input-number size="mini" v-model="policyForm.t111Rate" :precision="4" :step="0.0001" :min="policyForm.t111RateMin" :max="1"></el-input-number>
            <span> %</span>
            <span class="p-l-20">(最低刷卡借记卡费率：{{ policyForm.t111RateMin }} %)</span>
          </div>

          <div class="haruyuki-line-height-special haruyuki-plr-40 line_top">
            <span>刷卡借记卡封顶金额：</span>
            <span> {{ policyForm.d011RateTop }} 元 </span>
            <span class="p-l-20">(最低刷卡借记卡封顶金额：{{ policyForm.d011RateTopMin }} 元)</span>
          </div>
         
        </template>


        <!-- </div> -->
      </template>
      <span slot="footer" class="dialog-footer">
        <el-button icon="el-icon-check" size="small" type="primary" v-preventClick @click.stop="submitPolicyForm">提 交</el-button>
      </span>
    </el-dialog>
  </basic-container>
</template>

<script>
import {
  add,
  remove,
  getExportTemplate,
  incomingTerminalOn
} from "@/api/rb-service/terminal/terminal";

import {
  getList,
  selectModelList,
  minPolicy,
  submitPolicy,
  apiTongDao,
  getPosExport
} from "@/api/rb-service/store/store";
import { mapGetters } from "vuex";
import { downloadFileExcel } from "@/util/util";
import selectPage from "@/components/select-page/select-page";

var serviceDic = [{
  label: '包含下级',
  value: 1
}]
export default {
  components: {
    selectPage,
  },
  props: {
    rptNo: {
      type: String,
      required: true,
      default: '20'
    }
  },
  data() {
    return {
      form: {},
      query: {},
      search: {},
      loading: true,
      excelBox: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      selectionList: [],
      option: {
        height: "calc(50vh - 50px)",
        calcHeight: 30,
        tip: false,
        border: true,
        index: true,
        viewBtn: false,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        // searchIndex: 3, //从第三个后隐藏 searchIcon
        // searchIcon: true, //显示搜索 展开/隐藏按钮
        // searchLabelWidth:120,
        selection: false,
        // searchMenuSpan: 6,
        columnBtn: false,
        menu: true,
        menuWidth: 100,
        column: [
          {
            label: "服务商编号",
            searchLabel: "服务商",
            prop: "serviceNo",
            type: 'select',
            search: true,
            hide: true,
            minWidth: 110,
            overHidden: true,
            searchOrder: 0,
            rules: [
              {
                required: true,
                message: "请输入服务商编号",
                trigger: "blur",
              },
            ],
          },
          {
            label: "服务商编号",
            prop: "rsServiceNo",
            type: "input",
            minWidth: 110,
            overHidden: true,
            rules: [
              {
                required: true,
                message: "请输入服务商编号",
                trigger: "blur",
              }
            ]
          },
          {
            label: '',
            prop: 'isAllSer',
            type: 'select',
            multiple: false,
            dataType: "string",
            showColumn: false,
            hide: true,
            search: true,
            searchType: "checkbox",
            searchOrder: 0,
            searchSpan: 0,
            searchLabelWidth: '0',
            dicData: serviceDic
          },
          {
            label: "服务商名称",
            prop: "rsServiceName",
            type: "input",
            width: 200,
            display: false,
            rules: [
              {
                required: true,
                message: "请输入服务商名称",
                trigger: "blur",
              }
            ],
            overHidden: true
          },
          {
            label: "所属机构",
            prop: "orgNo",
            type: "select",
            dataType: "string",
            showColumn: false,
            search: true,
            filterable: true,
            hide: true,
            rules: [
              {
                required: true,
                message: "请选择所属机构",
                trigger: "blur",
              }
            ]
          },

          {
            label: "品牌",
            prop: "rpsNo",
            type: "select",
            search: true,
            hide: true,
            dicUrl: "/api/rb-service/service/store/store/selectSupList?current=-1&size=-1&rptNo=20",
            props: {
              label: "rpsName",
              value: "rpsNo",
              desc: "rpsNo"
            },
            change: (row) => {
              if (row.value) {
                // 获取供应商
                this.form.rpmNo = '';
                this.search.rpmNo = '';
                selectModelList(-1, -1, { rpsNo: row.value, rptNo: this.rptNo }).then((res) => {
                  const column = this.findObject(this.option.column, "rpmNo");
                  column.dicData = res.data.data;
                })
              }
            },
            rules: [
              {
                required: true,
                message: "请选择品牌",
                trigger: "blur",
              }
            ]
          },
          {
            label: "品牌",
            prop: "rpsName",
            type: "input",
            rules: [
              {
                required: true,
                message: "请输入品牌",
                trigger: "blur",
              }
            ],
            overHidden: true,
            minWidth: 110
          },
          {
            label: "型号",
            prop: "rpmNo",
            type: "select",
            search: true,
            hide: true,
            dicUrl: "/api/rb-service/service/store/store/selectModelList?current=-1&size=-1&rptNo=20",
            props: {
              label: "rpmName",
              value: "rpmNo",
              desc: "rpmNo"
            },
            rules: [
              {
                required: true,
                message: "请选择型号",
                trigger: "blur",
              }
            ]
          },
          {
            label: "型号",
            prop: "rpmName",
            type: "input",
            rules: [
              {
                required: true,
                message: "请输入型号",
                trigger: "blur",
              }
            ],
            overHidden: true,
            minWidth: 110
          },

          {
            label: "SN编号",
            prop: "rsSn",
            type: "input",
            search: true,
            rules: [
              {
                required: true,
                message: "请输入SN编号",
                trigger: "blur",
              }
            ],
            overHidden: true,
            minWidth: 160
          },

          {
            label: "流量卡金额",
            prop: "simAmount",
            type: "input",
            overHidden: true,
            minWidth: 100
          },
          {
            label: "商户编号",
            searchLabel: "商户",
            prop: "rpiNo",
            type: 'select',
            width: 140,
            search: true,
            overHidden: true
          },
          {
            label: "门头名称",
            prop: "rpiName",
            type: "input",
            overHidden: true
          },
          {
            label: "业务类型",
            prop: "businessType",
            // slot: true,
            display: false,
            minWidth: 120,
            overHidden: true
          },
          {
            label: "业务类型名称",
            prop: "businessTypeName",
            // slot: true,
            display: false,
            minWidth: 140,
            overHidden: true
          },
          {
            label: "活动名称",
            prop: "activeName",
            type: "input",
            width: 140,
            overHidden: true
          },
          {
            label: "调拨状态",
            prop: "amount",
            type: "select",
            dicUrl: "/api/blade-system/dict/dictionary?code=amount_state",
            props: {
              label: "dictValue",
              value: "dictKey",
            },
            dataType: "string",
            search: true,
            showColumn: false,
            display: false,
            rules: [
              {
                required: true,
                message: "请输入调拨状态",
                trigger: "blur",
              },
            ],
          },
          {
            label: "设备状态",
            searchLabel: "是否绑定",
            prop: "isBind",
            type: "select",
            search: true,
            searchOrder: 22,
            dicUrl: "/api/blade-system/dict/dictionary?code=is_bind",
            props: {
              label: "dictValue",
              value: "dictKey",
            },
            rules: [
              {
                required: true,
                message: "请选择设备状态",
                trigger: "blur",
              },
            ],
          },
          {
            label: "入库日期",
            prop: "createTime",
            type: "input",
            minWidth: 140,
            overHidden: true
          },
          {
            label: "绑定日期",
            prop: "bindTime",
            type: "input",
            minWidth: 140,
            overHidden:true,
          },
        ]
      },
      data: [],
      excelForm: {},
      excelOption: {
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: "模板上传",
            prop: "excelFile",
            type: "upload",
            drag: true,
            loadText: "模板上传中，请稍等",
            span: 24,
            propsHttp: {
              res: "data",
            },
            tip: "请上传 .xls,.xlsx 标准格式文件",
            action: "/api/rb-oem/terminal/terminal/import",
          },
          {
            label: "模板下载",
            prop: "excelTemplate",
            formslot: true,
            span: 24,
          }
        ]
      },
      policyVisible: false,//费率模态框
      policyForm: {
        wechatSignRate: 0,//微信费率
        wechatSignRateMin: 0,//微信费率（最低）
        alipaySignRate: 0,//支付宝费率
        alipaySignRateMin: 0,//支付宝费率（最低）
        debitRate2: 0,//借记卡优惠费率
        debitRate2Min: 0,//借记卡优惠费率（最低）
        creditRate2: 0,//贷记卡优惠费率
        creditRate2Min: 0,//贷记卡优惠费率（最低）
        unionpayRate: 0,//银联费率
        unionpayRateMin: 0,//银联费率（最低）
        t111Rate: 0,//刷卡借记卡费率
        t111RateMin: 0,//刷卡借记卡费率（最低）
        d011RateTop: 0,//刷卡借记卡封顶金额
        d011RateTopMin: 0,//刷卡借记卡封顶金额（最低）
        t112Rate: 0,//刷卡贷记卡费率
        t112RateMin: 0,//刷卡贷记卡费率（最低）
      },//费率表单
      tongDao: [],
      aisleCode: ""
    };
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.store_add, false),
        viewBtn: this.vaildData(this.permission.store_view, false),
        delBtn: this.vaildData(this.permission.store_delete, false),
        editBtn: this.vaildData(this.permission.store_edit, false),
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(",");
    },
    getColor() {
      return state => {
        if (state == '0') {
          return '#F56C6C';
        } else if (state == '1') {
          return '#67C23A';
        }
      }
    },
    getColorStatus() {
      return state => {
        if (state == '0') {
          return '#E6A23C';
        } else if (state == '1') {
          return '#67C23A';
        }
      }
    },
    isMuen() {
      return val => {
        return this.tongDao.includes(val)
      }
    }
  },
  created() {
    this.getTongDao();
  },
  methods: {
    getTongDao() {
      apiTongDao().then(res => {
        let data = res.data.data.list;
        data.forEach((item) => {
          this.tongDao.push(item.aisleCode)
        })
      })
    },
    /**
     * @func 机具费率_提交
     * */
    submitPolicyForm() {
      let that = this;
      submitPolicy(this.policyForm).then(res => {
        this.$message({ type: "success", message: res.data.msg });
        that.policyVisible = false;
        this.initPolicyForm();
      })
    },
    /**
     * @func 机具费率表单初始化
     * */
    initPolicyForm() {
      this.policyForm = {
        wechatSignRate: 0,//微信费率
        wechatSignRateMin: 0,//微信费率（最低）
        alipaySignRate: 0,//支付宝费率
        alipaySignRateMin: 0,//支付宝费率（最低）
        debitRate2: 0,//借记卡优惠费率
        debitRate2Min: 0,//借记卡优惠费率（最低）
        creditRate2: 0,//贷记卡优惠费率
        creditRate2Min: 0,//贷记卡优惠费率（最低）
        unionpayRate: 0,//银联费率
        unionpayRateMin: 0,//银联费率（最低）
        t111Rate: 0,//刷卡借记卡费率
        t111RateMin: 0,//刷卡借记卡费率（最低）
        d011RateTop: 0,//刷卡借记卡封顶金额
        d011RateTopMin: 0,//刷卡借记卡封顶金额（最低）
        t112Rate: 0,//刷卡贷记卡费率
        t112RateMin: 0,//刷卡贷记卡费率（最低）
      }
    },
    /**
     * @func 关闭_机具费率模态框回调
     * */
    policyHandleClose(done) {
      // 机具费率模态框回调 需要初始化
      this.initPolicyForm();
      done();
    },
    /**
     * @func 机具费率模态框_开关
     * */
    setPolicyVisible(row) {
      let that = this;
      this.aisleCode = row.aisleCode;
      minPolicy(row.aisleCode, row.rsSn).then((res) => {
        that.policyForm = res.data.data;
        that.policyForm.aisleCode = row.aisleCode;
        that.policyForm.sn = row.rsSn;

        that.policyVisible = true;
      }, (error) => {
        that.policyVisible = false;
        window.console.log(error)
      })
    },
    /**
     * @func 入库
     * @desc 点击入库进入入库界面
     * */
    handleStorage() {
      this.$router.push({
        name: "库存入库",
        query: {
          rptNo: this.rptNo
        },
      });
    },
    /**
     * @func 调拨
     * @desc 点击调拨进入调拨界面
     * */
    handleAllot() {
      this.$router.push({
        name: "库存调拨",
        query: {
          e: this.$crypto.encrypt(JSON.stringify({
            rptNo: this.rptNo,
            stockType: 'pos'
          }))
        }
      });
    },
    /**
     * @func 回拨
     * @desc 点击回拨进入回拨界面
     * */
    handleRebate() {
      this.$router.push({
        name: "库存回拨",
        query: {
          rptNo: this.rptNo
        }
      });
    },
    /**
     * @func 详情
     * @desc 点击详情进入详情界面
     * @param {Object} row - 商户信息
     * */
    handleDetail(row) {
      this.$router.push({
        name: "商户详情",
        query: {
          rpiNo: row.rpiNo,
          rpiExStatus: row.rpiExStatus
        },
      });
    },
    /**
     * @func 终端状态开关
     * @desc 终端状态开关 0否 1是
     * @param {Object} row - 终端信息
     * */
    handleSwitch(row) {
      incomingTerminalOn(row.id, row.isOn).then(
        () => { },
        (error) => {
          row.isOn = row.isOn == 1 ? 0 : 1;
          window.console.log(error);
        }
      );
    },
    /**
     * @func 设备管理
     * @desc 点击设备管理进入设备管理界面
     * @param {Object} row - 仓库信息
     * */
    handleDevice(row) {
      this.$router.push({
        name: "设备管理",
        query: {
          rpiNo: row.rpiNo
        }
      });
    },
    /**
     * @func 商户详情
     * @desc 点击商户编号进入商户详情界面(登记商户)
     * @param {Object} row - 数据信息
     * */
    handleMarchantDetails(row) {
      this.$router.push({
        path: "/rb-service/posinfo/pos_info_reg_details",
        query: {
          d: this.$crypto.encrypt(JSON.stringify({
            rpiNo: row.rpiNo,
          }))
        }
      });
    },
    rowSave(row, done, loading) {
      add(row).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
        },
        (error) => {
          loading();
          window.console.log(error);
        }
      );
    },
    /* rowUpdate(row, index, done, loading) {
      update(row).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
        },
        (error) => {
          loading();
          window.console.log(error);
        }
      );
    }, */
    rowDel(row) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return remove(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        });
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return remove(this.ids);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          this.$refs.crud.toggleSelection();
        });
    },
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        // getDetail(this.form.id).then((res) => {
        //   this.form = res.data.data;
        // });
      }
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      getList(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query, { rptNo: this.rptNo })
      ).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    },
    handleImport() {
      this.excelBox = true;
    },
    handleExport() {
      this.$confirm("是否导出用户数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        getPosExport(this.search).then((res) => {
          this.$message({ type: "success", message: res.data.msg });
        },
          (error) => {
            window.console.log(error);
          }
        );
      });
    },
    handleTemplate() {
      getExportTemplate().then((res) => {
        downloadFileExcel(res);
      },
        (error) => {
          window.console.log(error);
        }
      );
    },
    uploadAfter(res, done) {
      this.excelBox = false;
      this.refreshChange();
      done();
    },
    sortChange(val) {
      if (val.order == "ascending") {
        //正序
        this.query.ascs = val.prop;
        this.query.descs = "";
      } else {
        //倒序
        this.query.descs = val.prop;
        this.query.ascs = "";
      }
      this.refreshChange();
    }
  }
};
</script>

<style lang="scss" scoped>
/deep/ .el-tag--dark.el-tag--success {
  border-color: transparent;
  opacity: 0.8;
}

.line_top {
  border-top: 1px solid #e0eafc;
}

.p-l-20 {
  padding-left: 20px;
}
</style>
